﻿namespace PrimeNumber
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入质数的范围： ");
            int n = int.Parse(Console.ReadLine());
            int i, j, max = 0;
            bool flag = false;
            //开始计时
            DateTime beginTime = DateTime.Now;
            for (i = n; i > 2; i--)
            {
                flag = false;
                for (j = 2; j < (i / 2); j++)
                {
                    if (i % j == 0)
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag == false)
                {
                    max = i;
                    break;
                }
            }

            Console.WriteLine($"最大的质数为{max}");
            DateTime afterTime = DateTime.Now;
            TimeSpan timeSpan = afterTime - beginTime;
            Console.WriteLine("运行时间为： " + timeSpan.TotalSeconds);
        }
    }
}